package com.quintilis31.home.aspect;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * Logging Aspect for the Quintilis31 set
 * of projects
 * User: Jothi Shankar Kumar. S
 * Date: Dec 8, 2010
 * Time: 9:06:09 PM
 * To change this template use File | Settings | File Templates.
 */
@Aspect
public final class LoggingAspect {

    /** The Logger implementation for this class. */
    private static final Logger LOG = Logger.getLogger(LoggingAspect.class);

    @Pointcut("within(com.quintilis31.home..*)")
    private void traceAllClasses() {}

    @Pointcut("execution(public * *(..))")
    private void traceAllPublicMethods() {}

    @Pointcut("traceAllClasses() && traceAllPublicMethods()")
    private void traceAllPublicMethodsInAllClasses() {}

    @Pointcut("within(com.quintilis31.home.core.content.service.impl.ContentServiceImpl) && " +
              "within(com.quintilis31.home.core.user.service.impl.UserServiceImpl)")
    private void traceAllServiceMethodsForReturnValue() {}

    @Before("traceAllPublicMethodsInAllClasses()")
    public void traceBefore(JoinPoint jp) {
        LOG.info("Before: In Class: " + jp.getTarget().getClass() + " : " + "Method : " + jp.getSignature().getName());
    }

    @After("traceAllPublicMethodsInAllClasses()")
    public void traceAfter(JoinPoint jp) {
        LOG.info("After: In Class: " + jp.getTarget().getClass() + " : " + "Method : " + jp.getSignature().getName());
    }

    @AfterReturning(pointcut="traceAllServiceMethodsForReturnValue()", returning="retVal")
    public void traceAfterReturning(Object retVal) {
        LOG.info("Printing Return Value After Returning: " + retVal);
    }

}
